package com.jprocms.module.cms.dal.mysql.investigate;

import com.jpro.framework.common.pojo.PageResult;
import com.jpro.framework.mybatis.core.mapper.BaseMapperX;
import com.jpro.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.jprocms.module.cms.controller.admin.investigate.vo.InvestigateListReqVO;
import com.jprocms.module.cms.controller.admin.investigate.vo.InvestigatePageReqVO;
import com.jprocms.module.cms.dal.dataobject.investigate.InvestigateDO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.util.Collection;
import java.util.List;

/**
 * 问卷调查 Mapper
 *
 * @author jprocms
 */
@Mapper
public interface InvestigateMapper extends BaseMapperX<InvestigateDO> {
    /**
     * 根据主键获取数据
     *
     * @param id 主键ID
     * @return 实体对象。没有找到数据，则返回 {@code null}
     */
    InvestigateDO select(Long id);

    IPage<InvestigateDO> selectPage(@Param("params") InvestigatePageReqVO params, @Param("orders") Collection<OrderItem> orders, IPage<InvestigateDO> page);

    List<InvestigateDO> selectList(@Param("params") InvestigateListReqVO params, @Param("orders") Collection<OrderItem> orders);


    /**
     * 投票
     *
     * @param id 调查问卷ID
     * @return 更新条数
     */
    int vote(@Param("id") Long id);

    /**
     * 根据站点ID删除数据
     *
     * @param siteId 站点ID
     * @return 被删除的数据条数
     */
    int deleteBySiteId(Long siteId);


    default PageResult<InvestigateDO> selectPage(InvestigatePageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<InvestigateDO>()
                .eqIfPresent(InvestigateDO::getSiteId, reqVO.getSiteId())
                .eqIfPresent(InvestigateDO::getTitle, reqVO.getTitle())
                .betweenIfPresent(InvestigateDO::getBeginDate, reqVO.getBeginDate())
                .betweenIfPresent(InvestigateDO::getEndDate, reqVO.getEndDate())
                .eqIfPresent(InvestigateDO::getEnabled, reqVO.getEnabled())
                .orderByDesc(InvestigateDO::getId));
    }

    default List<InvestigateDO> selectList(InvestigateListReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<InvestigateDO>()
                .eqIfPresent(InvestigateDO::getSiteId, reqVO.getSiteId())
                .eqIfPresent(InvestigateDO::getTitle, reqVO.getTitle())
                .betweenIfPresent(InvestigateDO::getBeginDate, reqVO.getBeginDate())
                .betweenIfPresent(InvestigateDO::getEndDate, reqVO.getEndDate())
                .eqIfPresent(InvestigateDO::getEnabled, reqVO.getEnabled())
                .orderByDesc(InvestigateDO::getId));
    }


}
